"""
分块配置管理

负责管理文档分块相关的配置。
"""

from typing import Dict, Any

from .base_config import BaseConfig
from .enums import ChunkStrategy


class ChunkingConfig(BaseConfig):
    """分块配置管理类"""

    @property
    def strategy(self) -> ChunkStrategy:
        """分块策略"""
        strategy_str = self._get_env("CHUNK_STRATEGY", "semantic").lower()
        try:
            return ChunkStrategy(strategy_str)
        except ValueError:
            raise ValueError(f"无效的分块策略: {strategy_str}")

    @property
    def chunk_size(self) -> int:
        """分块大小"""
        return self._get_env_int("CHUNK_SIZE", 1024)

    @property
    def chunk_overlap(self) -> int:
        """分块重叠"""
        return self._get_env_int("CHUNK_OVERLAP", 100)

    @property
    def min_chunk_size(self) -> int:
        """最小分块大小"""
        return self._get_env_int("MIN_CHUNK_SIZE", 50)

    @property
    def max_chunk_size(self) -> int:
        """最大分块大小"""
        return self._get_env_int("MAX_CHUNK_SIZE", 2048)

    @property
    def semantic_chunk_threshold(self) -> float:
        """语义分块阈值"""
        return self._get_env_float("SEMANTIC_CHUNK_THRESHOLD", 0.7)

    @property
    def semantic_chunk_similarity_window_size(self) -> int:
        """语义分块相似度窗口大小"""
        return self._get_env_int("SEMANTIC_CHUNK_SIMILARITY_WINDOW_SIZE", 3)

    @property
    def max_concurrent_chunking(self) -> int:
        """最大并发分块数"""
        return self._get_env_int("MAX_CONCURRENT_CHUNKING", 4)

    def get_config(self) -> Dict[str, Any]:
        """获取完整分块配置"""
        return {
            "strategy": self.strategy.value,
            "chunk_size": self.chunk_size,
            "chunk_overlap": self.chunk_overlap,
            "min_chunk_size": self.min_chunk_size,
            "max_chunk_size": self.max_chunk_size,
            "semantic_chunk_threshold": self.semantic_chunk_threshold,
            "semantic_chunk_similarity_window_size": self.semantic_chunk_similarity_window_size,
            "max_concurrent_chunking": self.max_concurrent_chunking
        }